{
  "nbformat": 4,
  "nbformat_minor": 0,
  "metadata": {
    "colab": {
      "name": "Strings.ipynb",
      "version": "0.3.2",
      "provenance": [],
      "collapsed_sections": [],
      "include_colab_link": true
    },
    "kernelspec": {
      "name": "python3",
      "display_name": "Python 3"
    }
  },
  "cells": [
    {
      "cell_type": "markdown",
      "metadata": {
        "id": "view-in-github",
        "colab_type": "text"
      },
      "source": [
        "<a href=\"https://colab.research.google.com/github/Tanu-N-Prabhu/Python/blob/master/Strings/Strings.ipynb\" target=\"_parent\"><img src=\"https://colab.research.google.com/assets/colab-badge.svg\" alt=\"Open In Colab\"/></a>"
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {
        "id": "zlnHLnmRMY8l",
        "colab_type": "text"
      },
      "source": [
        "# Python Strings from Scratch !!"
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {
        "id": "xxh853OvayXm",
        "colab_type": "text"
      },
      "source": [
        "## Let us understand the fundamentals of strings in python."
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {
        "id": "kSUR6_XRMvHA",
        "colab_type": "text"
      },
      "source": [
        "![alt text](https://www.gangboard.com/blog/wp-content/uploads/2019/05/Strings-in-Python.jpg)"
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {
        "id": "9Dsy0iRC_NiG",
        "colab_type": "text"
      },
      "source": [
        "Strings are a sequence of characters which can be stored either as a constant or a different variable. Strings are considered as a datatype. Typically, programmers must enclose strings in quotation marks for the data to recognized as a string and not a number or variable name. Shown below are some of the most used string methods on a daily basis and are one of the most commonly asked interview questions."
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {
        "id": "pIY4aKtgbNAV",
        "colab_type": "text"
      },
      "source": [
        "### For example, declaring a string in python:"
      ]
    },
    {
      "cell_type": "code",
      "metadata": {
        "id": "BIGc-dwobOzs",
        "colab_type": "code",
        "outputId": "0addf3da-8c9a-408e-ff65-47c26e338a45",
        "colab": {
          "base_uri": "https://localhost:8080/",
          "height": 35
        }
      },
      "source": [
        "# Declaring a string variable\n",
        "string = \"This is a python tutorial\"\n",
        "print(string)"
      ],
      "execution_count": 0,
      "outputs": [
        {
          "output_type": "stream",
          "text": [
            "This is a python tutorial\n"
          ],
          "name": "stdout"
        }
      ]
    },
    {
      "cell_type": "code",
      "metadata": {
        "id": "sOgqU15TbRP6",
        "colab_type": "code",
        "outputId": "3d7c0ea5-ae76-4506-d093-804e3214cb80",
        "colab": {
          "base_uri": "https://localhost:8080/",
          "height": 35
        }
      },
      "source": [
        "print(type(string))"
      ],
      "execution_count": 0,
      "outputs": [
        {
          "output_type": "stream",
          "text": [
            "<class 'str'>\n"
          ],
          "name": "stdout"
        }
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {
        "id": "SGLhburabSbf",
        "colab_type": "text"
      },
      "source": [
        "\n",
        "\n",
        "---\n",
        "\n"
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {
        "id": "bKV_oUeUbT9G",
        "colab_type": "text"
      },
      "source": [
        "## 1. Escape sequence  in python using strings"
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {
        "id": "JmieNp0cbVpO",
        "colab_type": "text"
      },
      "source": [
        "In Python strings, the backslash \" \" is a special character, also called the \"escape\" character. It is used in representing certain whitespace characters: \"\\t\" is a tab, \"\\n\" is a new line, and \"\\r\" is a carriage return. Finally, \" \" can be used to escape itself: \"\\\" is the literal backslash character. "
      ]
    },
    {
      "cell_type": "code",
      "metadata": {
        "id": "iqAlH3DHbYfB",
        "colab_type": "code",
        "outputId": "f37893b8-ef66-4b97-ef1c-f4f99dd7878c",
        "colab": {
          "base_uri": "https://localhost:8080/",
          "height": 35
        }
      },
      "source": [
        "# THis is an escape sequence.\n",
        "string = \"This is a \\\"Google Colab\\\" python notebook\"\n",
        "print(string)"
      ],
      "execution_count": 0,
      "outputs": [
        {
          "output_type": "stream",
          "text": [
            "This is a \"Google Colab\" python notebook\n"
          ],
          "name": "stdout"
        }
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {
        "id": "KeMt-LXtba_w",
        "colab_type": "text"
      },
      "source": [
        "\n",
        "\n",
        "---\n",
        "\n"
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {
        "id": "i6uHC1G_bcpD",
        "colab_type": "text"
      },
      "source": [
        "## 2. Accessing the String by an Index"
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {
        "id": "f_SWqIkNbdsF",
        "colab_type": "text"
      },
      "source": [
        "Strings can be accessed by their index in order to get the value. To do this all you have to do is just place the number (index value) inside the pair of square brackets along with the name of the string."
      ]
    },
    {
      "cell_type": "code",
      "metadata": {
        "id": "mIpJw2iRbf4d",
        "colab_type": "code",
        "outputId": "fc3bce1d-63d3-44f0-a7ff-d8ddeb3cb047",
        "colab": {
          "base_uri": "https://localhost:8080/",
          "height": 35
        }
      },
      "source": [
        "string = \"Python\"\n",
        "print(string[2])"
      ],
      "execution_count": 0,
      "outputs": [
        {
          "output_type": "stream",
          "text": [
            "t\n"
          ],
          "name": "stdout"
        }
      ]
    },
    {
      "cell_type": "code",
      "metadata": {
        "id": "DHBwL7TYbhVi",
        "colab_type": "code",
        "outputId": "39dbd53e-a463-4273-a027-eed1a732d16c",
        "colab": {
          "base_uri": "https://localhost:8080/",
          "height": 35
        }
      },
      "source": [
        "print(string[5])"
      ],
      "execution_count": 0,
      "outputs": [
        {
          "output_type": "stream",
          "text": [
            "n\n"
          ],
          "name": "stdout"
        }
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {
        "id": "nRlzW6W4biG6",
        "colab_type": "text"
      },
      "source": [
        "\n",
        "\n",
        "---\n",
        "\n"
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {
        "id": "035PEbyEbiyF",
        "colab_type": "text"
      },
      "source": [
        "## 3. Slicing a string"
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {
        "id": "-bb6K9SzblDR",
        "colab_type": "text"
      },
      "source": [
        "Slicing a string helps to get a set of characters from a string. This is really helpful when we want to access a particular set of characters in a string. Below are some slicing variants that are useful."
      ]
    },
    {
      "cell_type": "code",
      "metadata": {
        "id": "aw6PN6nubmyp",
        "colab_type": "code",
        "outputId": "2b1b70c5-3b24-4b62-df8f-e2122d25ed0f",
        "colab": {
          "base_uri": "https://localhost:8080/",
          "height": 35
        }
      },
      "source": [
        "string = \"programming\"\n",
        "string"
      ],
      "execution_count": 0,
      "outputs": [
        {
          "output_type": "execute_result",
          "data": {
            "text/plain": [
              "'programming'"
            ]
          },
          "metadata": {
            "tags": []
          },
          "execution_count": 6
        }
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {
        "id": "Cjc64ZDMbt5V",
        "colab_type": "text"
      },
      "source": [
        "**Getting  one character of the string**"
      ]
    },
    {
      "cell_type": "code",
      "metadata": {
        "id": "MKV05Uclbomv",
        "colab_type": "code",
        "outputId": "eae81339-d6e1-482e-88a9-d2d459c45be6",
        "colab": {
          "base_uri": "https://localhost:8080/",
          "height": 35
        }
      },
      "source": [
        "print(string[0:1])"
      ],
      "execution_count": 0,
      "outputs": [
        {
          "output_type": "stream",
          "text": [
            "p\n"
          ],
          "name": "stdout"
        }
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {
        "id": "VqE7vaT7bwwW",
        "colab_type": "text"
      },
      "source": [
        "**Getting the first three characters from the string**"
      ]
    },
    {
      "cell_type": "code",
      "metadata": {
        "id": "GfhGuOGXbykG",
        "colab_type": "code",
        "outputId": "4ab8b481-9271-42ef-9e3f-31a700e73019",
        "colab": {
          "base_uri": "https://localhost:8080/",
          "height": 35
        }
      },
      "source": [
        "print(string[0:3])"
      ],
      "execution_count": 0,
      "outputs": [
        {
          "output_type": "stream",
          "text": [
            "pro\n"
          ],
          "name": "stdout"
        }
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {
        "id": "INQoq6VKb056",
        "colab_type": "text"
      },
      "source": [
        "**Getting the first three characters from the string (Alternate)**"
      ]
    },
    {
      "cell_type": "code",
      "metadata": {
        "id": "c5Qtr3qAb1or",
        "colab_type": "code",
        "outputId": "1f762eeb-c3e6-4b57-dfbc-5f1bd29036b9",
        "colab": {
          "base_uri": "https://localhost:8080/",
          "height": 35
        }
      },
      "source": [
        "print(string[:3])"
      ],
      "execution_count": 0,
      "outputs": [
        {
          "output_type": "stream",
          "text": [
            "pro\n"
          ],
          "name": "stdout"
        }
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {
        "id": "LqmBatu1b4B3",
        "colab_type": "text"
      },
      "source": [
        "**Getting the last three characters from the string**"
      ]
    },
    {
      "cell_type": "code",
      "metadata": {
        "id": "NP01nD-Fb4rI",
        "colab_type": "code",
        "outputId": "a4c961af-55a8-4777-e7d1-559432d53f5b",
        "colab": {
          "base_uri": "https://localhost:8080/",
          "height": 35
        }
      },
      "source": [
        "print(string[-3:])"
      ],
      "execution_count": 0,
      "outputs": [
        {
          "output_type": "stream",
          "text": [
            "ing\n"
          ],
          "name": "stdout"
        }
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {
        "id": "CFHrPtA1b7P2",
        "colab_type": "text"
      },
      "source": [
        "**Getting all characters but excluding three first characters from the string**"
      ]
    },
    {
      "cell_type": "code",
      "metadata": {
        "id": "GWyjj-T-b64y",
        "colab_type": "code",
        "outputId": "247aaf75-e9b5-4cbc-8810-e5b31873c112",
        "colab": {
          "base_uri": "https://localhost:8080/",
          "height": 35
        }
      },
      "source": [
        "print(string[3:])"
      ],
      "execution_count": 0,
      "outputs": [
        {
          "output_type": "stream",
          "text": [
            "gramming\n"
          ],
          "name": "stdout"
        }
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {
        "id": "u7xEgZUbcAe6",
        "colab_type": "text"
      },
      "source": [
        "**Getting all characters but excluding the last three characters from the string**"
      ]
    },
    {
      "cell_type": "code",
      "metadata": {
        "id": "eSaTVepRcB_u",
        "colab_type": "code",
        "outputId": "69050ad0-1f57-4cbd-ce5f-8e2c8088bff2",
        "colab": {
          "base_uri": "https://localhost:8080/",
          "height": 35
        }
      },
      "source": [
        "print(string[:-3])"
      ],
      "execution_count": 0,
      "outputs": [
        {
          "output_type": "stream",
          "text": [
            "programm\n"
          ],
          "name": "stdout"
        }
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {
        "id": "NZ25LjX_cFTN",
        "colab_type": "text"
      },
      "source": [
        "**Reversing all the characters in a given string**"
      ]
    },
    {
      "cell_type": "code",
      "metadata": {
        "id": "rTcC5ghscDnM",
        "colab_type": "code",
        "outputId": "2180d576-ed54-472d-922d-de1842a0181f",
        "colab": {
          "base_uri": "https://localhost:8080/",
          "height": 35
        }
      },
      "source": [
        "print(string[::-1])"
      ],
      "execution_count": 0,
      "outputs": [
        {
          "output_type": "stream",
          "text": [
            "gnimmargorp\n"
          ],
          "name": "stdout"
        }
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {
        "id": "_ZQsR8s3cIzp",
        "colab_type": "text"
      },
      "source": [
        "**Alternative to printing all characters in a string**"
      ]
    },
    {
      "cell_type": "code",
      "metadata": {
        "id": "UhQyXlXucIMf",
        "colab_type": "code",
        "outputId": "0b2e432a-6fb6-42a1-ddd0-34d3bf081ed5",
        "colab": {
          "base_uri": "https://localhost:8080/",
          "height": 35
        }
      },
      "source": [
        "print(string[::])"
      ],
      "execution_count": 0,
      "outputs": [
        {
          "output_type": "stream",
          "text": [
            "programming\n"
          ],
          "name": "stdout"
        }
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {
        "id": "zgUsB_khcL1H",
        "colab_type": "text"
      },
      "source": [
        "\n",
        "\n",
        "---\n",
        "\n"
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {
        "id": "1IxFIjOTcMaj",
        "colab_type": "text"
      },
      "source": [
        "**4. Splitting a string**"
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {
        "id": "yy4X7tFHcO9B",
        "colab_type": "text"
      },
      "source": [
        "Sometimes splitting a string is a handy option because it is one of the easiest ways to convert a string into a list. I know I have not spoken about the list but keep in mind that split converts a string into a list. You can find the material on Python Lists that is written by me which can provide enough idea to master python lists [Python Lists](https://towardsdatascience.com/python-lists-from-scratch-4b958eb956fc)"
      ]
    },
    {
      "cell_type": "code",
      "metadata": {
        "id": "jL4s2MfxcUu2",
        "colab_type": "code",
        "outputId": "3ded15c0-4dfe-448d-8fe1-281f44d451f7",
        "colab": {
          "base_uri": "https://localhost:8080/",
          "height": 35
        }
      },
      "source": [
        "String = \"Computer Programming\"\n",
        "String"
      ],
      "execution_count": 0,
      "outputs": [
        {
          "output_type": "execute_result",
          "data": {
            "text/plain": [
              "'Computer Programming'"
            ]
          },
          "metadata": {
            "tags": []
          },
          "execution_count": 15
        }
      ]
    },
    {
      "cell_type": "code",
      "metadata": {
        "id": "FxMKh4RScXDY",
        "colab_type": "code",
        "outputId": "49794b2f-8114-4c1c-9b0e-e436967735e5",
        "colab": {
          "base_uri": "https://localhost:8080/",
          "height": 35
        }
      },
      "source": [
        "type(String)"
      ],
      "execution_count": 0,
      "outputs": [
        {
          "output_type": "execute_result",
          "data": {
            "text/plain": [
              "str"
            ]
          },
          "metadata": {
            "tags": []
          },
          "execution_count": 16
        }
      ]
    },
    {
      "cell_type": "code",
      "metadata": {
        "id": "w5EJQWtBcYx8",
        "colab_type": "code",
        "outputId": "575b9ecd-ecc2-438a-da05-51552567e265",
        "colab": {
          "base_uri": "https://localhost:8080/",
          "height": 35
        }
      },
      "source": [
        "list = String.split()\n",
        "list"
      ],
      "execution_count": 0,
      "outputs": [
        {
          "output_type": "execute_result",
          "data": {
            "text/plain": [
              "['Computer', 'Programming']"
            ]
          },
          "metadata": {
            "tags": []
          },
          "execution_count": 17
        }
      ]
    },
    {
      "cell_type": "code",
      "metadata": {
        "id": "P0yiY0cMcaEW",
        "colab_type": "code",
        "outputId": "c0ea073a-dcd1-4321-aaaa-5f0edb33251e",
        "colab": {
          "base_uri": "https://localhost:8080/",
          "height": 35
        }
      },
      "source": [
        "type(list)"
      ],
      "execution_count": 0,
      "outputs": [
        {
          "output_type": "execute_result",
          "data": {
            "text/plain": [
              "list"
            ]
          },
          "metadata": {
            "tags": []
          },
          "execution_count": 18
        }
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {
        "id": "7BdAXOI6cbq4",
        "colab_type": "text"
      },
      "source": [
        "\n",
        "\n",
        "---\n",
        "\n"
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {
        "id": "Xwybsw-dccVE",
        "colab_type": "text"
      },
      "source": [
        "## 5. Replacing a string"
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {
        "id": "JWA0gP58cfDN",
        "colab_type": "text"
      },
      "source": [
        "The Replace function in python is one of the best function that can be applied to strings. For example, shown below is a string \"Money\" we need to replace the dollar and the comma sign and this can be done as shown below."
      ]
    },
    {
      "cell_type": "code",
      "metadata": {
        "id": "Yr9uB9hqcgLr",
        "colab_type": "code",
        "outputId": "2ad561ea-8a70-45a9-e21d-4bd83ff2d28c",
        "colab": {
          "base_uri": "https://localhost:8080/",
          "height": 69
        }
      },
      "source": [
        "Money = '$113,678'\n",
        "print(Money)\n",
        "print(\"===========================\")\n",
        "print(type(Money))"
      ],
      "execution_count": 0,
      "outputs": [
        {
          "output_type": "stream",
          "text": [
            "$113,678\n",
            "===========================\n",
            "<class 'str'>\n"
          ],
          "name": "stdout"
        }
      ]
    },
    {
      "cell_type": "code",
      "metadata": {
        "id": "fsK018P2cjJ3",
        "colab_type": "code",
        "outputId": "f8bc3015-ecec-4f3a-a93e-ca4f63eb0e0c",
        "colab": {
          "base_uri": "https://localhost:8080/",
          "height": 35
        }
      },
      "source": [
        "Money = Money.replace('$', '')\n",
        "Money"
      ],
      "execution_count": 0,
      "outputs": [
        {
          "output_type": "execute_result",
          "data": {
            "text/plain": [
              "'113,678'"
            ]
          },
          "metadata": {
            "tags": []
          },
          "execution_count": 20
        }
      ]
    },
    {
      "cell_type": "code",
      "metadata": {
        "id": "ZQO19dD_cknA",
        "colab_type": "code",
        "outputId": "f3a71c90-1e6a-4b85-e5e5-b380e76019ac",
        "colab": {
          "base_uri": "https://localhost:8080/",
          "height": 35
        }
      },
      "source": [
        "Money = Money.replace(',', '')\n",
        "Money"
      ],
      "execution_count": 0,
      "outputs": [
        {
          "output_type": "execute_result",
          "data": {
            "text/plain": [
              "'113678'"
            ]
          },
          "metadata": {
            "tags": []
          },
          "execution_count": 21
        }
      ]
    },
    {
      "cell_type": "code",
      "metadata": {
        "id": "wEBAA-tscmHf",
        "colab_type": "code",
        "outputId": "fbac2778-3332-433c-b6cc-ecc382a46dfd",
        "colab": {
          "base_uri": "https://localhost:8080/",
          "height": 69
        }
      },
      "source": [
        "Money = int(Money)\n",
        "print(Money)\n",
        "print(\"===========================\")\n",
        "print(type(Money))"
      ],
      "execution_count": 0,
      "outputs": [
        {
          "output_type": "stream",
          "text": [
            "113678\n",
            "===========================\n",
            "<class 'int'>\n"
          ],
          "name": "stdout"
        }
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {
        "id": "FHiWQ19lc0tt",
        "colab_type": "text"
      },
      "source": [
        "\n",
        "\n",
        "---\n",
        "\n"
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {
        "id": "ZMUiizBfc1TR",
        "colab_type": "text"
      },
      "source": [
        "## 6. Join"
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {
        "id": "dU25fiyvc3eN",
        "colab_type": "text"
      },
      "source": [
        "The join function is python is used to join the string according to the specified pattern."
      ]
    },
    {
      "cell_type": "code",
      "metadata": {
        "id": "k3cho5Jfc4xY",
        "colab_type": "code",
        "outputId": "dd0d386a-ffdc-43f7-8139-0ca6e045b501",
        "colab": {
          "base_uri": "https://localhost:8080/",
          "height": 35
        }
      },
      "source": [
        "String = \"Python Programming is fun\"\n",
        "String"
      ],
      "execution_count": 0,
      "outputs": [
        {
          "output_type": "execute_result",
          "data": {
            "text/plain": [
              "'Python Programming is fun'"
            ]
          },
          "metadata": {
            "tags": []
          },
          "execution_count": 23
        }
      ]
    },
    {
      "cell_type": "code",
      "metadata": {
        "id": "on4SdAFAc6Sa",
        "colab_type": "code",
        "outputId": "97248c6e-7a27-429a-e7d9-5d53e1ca25eb",
        "colab": {
          "base_uri": "https://localhost:8080/",
          "height": 35
        }
      },
      "source": [
        "String = \" \".join(String)\n",
        "String"
      ],
      "execution_count": 0,
      "outputs": [
        {
          "output_type": "execute_result",
          "data": {
            "text/plain": [
              "'P y t h o n   P r o g r a m m i n g   i s   f u n'"
            ]
          },
          "metadata": {
            "tags": []
          },
          "execution_count": 24
        }
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {
        "id": "bugIq-mNc7uN",
        "colab_type": "text"
      },
      "source": [
        "\n",
        "\n",
        "---\n",
        "\n"
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {
        "id": "Yx7oyLtDc8XI",
        "colab_type": "text"
      },
      "source": [
        "## 7. Capitalize"
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {
        "id": "KBWt0P9xc99B",
        "colab_type": "text"
      },
      "source": [
        "The capitalize function capitalizes the first character in the word or a string."
      ]
    },
    {
      "cell_type": "code",
      "metadata": {
        "id": "OfsFhFp0c_Eo",
        "colab_type": "code",
        "outputId": "2f372a13-efaa-4ae7-c62d-2acad64c68a3",
        "colab": {
          "base_uri": "https://localhost:8080/",
          "height": 35
        }
      },
      "source": [
        "string = \"programming\"\n",
        "string"
      ],
      "execution_count": 0,
      "outputs": [
        {
          "output_type": "execute_result",
          "data": {
            "text/plain": [
              "'programming'"
            ]
          },
          "metadata": {
            "tags": []
          },
          "execution_count": 25
        }
      ]
    },
    {
      "cell_type": "code",
      "metadata": {
        "id": "ZUvy5wxZdA7w",
        "colab_type": "code",
        "outputId": "61476b2c-21d3-487b-a0b9-bdd2c30dd564",
        "colab": {
          "base_uri": "https://localhost:8080/",
          "height": 35
        }
      },
      "source": [
        "string = string.capitalize()\n",
        "string"
      ],
      "execution_count": 0,
      "outputs": [
        {
          "output_type": "execute_result",
          "data": {
            "text/plain": [
              "'Programming'"
            ]
          },
          "metadata": {
            "tags": []
          },
          "execution_count": 26
        }
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {
        "id": "yX5Qdr6ydCFa",
        "colab_type": "text"
      },
      "source": [
        "\n",
        "\n",
        "---\n",
        "\n"
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {
        "id": "sRgDZVrqdCuA",
        "colab_type": "text"
      },
      "source": [
        "## 8. Center"
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {
        "id": "AsqHZ9r2dEwx",
        "colab_type": "text"
      },
      "source": [
        "The center method returns a string which is padded with the specified character."
      ]
    },
    {
      "cell_type": "code",
      "metadata": {
        "id": "rRXoOdEAdGAW",
        "colab_type": "code",
        "outputId": "c3885d22-cbd4-45ed-e647-c443809e02b5",
        "colab": {
          "base_uri": "https://localhost:8080/",
          "height": 35
        }
      },
      "source": [
        "string = \"python\"\n",
        "string"
      ],
      "execution_count": 0,
      "outputs": [
        {
          "output_type": "execute_result",
          "data": {
            "text/plain": [
              "'python'"
            ]
          },
          "metadata": {
            "tags": []
          },
          "execution_count": 27
        }
      ]
    },
    {
      "cell_type": "code",
      "metadata": {
        "id": "9-07a01adIY-",
        "colab_type": "code",
        "outputId": "afd0f70f-1166-4ccd-acef-9371b2651795",
        "colab": {
          "base_uri": "https://localhost:8080/",
          "height": 35
        }
      },
      "source": [
        "print(string.center(15, '*'))"
      ],
      "execution_count": 0,
      "outputs": [
        {
          "output_type": "stream",
          "text": [
            "*****python****\n"
          ],
          "name": "stdout"
        }
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {
        "id": "WirqOMPmdJrb",
        "colab_type": "text"
      },
      "source": [
        "\n",
        "\n",
        "---\n",
        "\n"
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {
        "id": "mMxEPvbudKPZ",
        "colab_type": "text"
      },
      "source": [
        "## 9. Find"
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {
        "id": "615CsWgodMU3",
        "colab_type": "text"
      },
      "source": [
        "The find method returns the index of the given substring position. If the value is not found it returns, -1."
      ]
    },
    {
      "cell_type": "code",
      "metadata": {
        "id": "YoNlax-LdOGs",
        "colab_type": "code",
        "outputId": "e66ad321-429e-468c-9a38-0297deced908",
        "colab": {
          "base_uri": "https://localhost:8080/",
          "height": 35
        }
      },
      "source": [
        "string = \"programming\"\n",
        "string"
      ],
      "execution_count": 0,
      "outputs": [
        {
          "output_type": "execute_result",
          "data": {
            "text/plain": [
              "'programming'"
            ]
          },
          "metadata": {
            "tags": []
          },
          "execution_count": 29
        }
      ]
    },
    {
      "cell_type": "code",
      "metadata": {
        "id": "UF1zGdSfdPl4",
        "colab_type": "code",
        "outputId": "039e43d5-a38a-42af-8893-21503d58f89e",
        "colab": {
          "base_uri": "https://localhost:8080/",
          "height": 35
        }
      },
      "source": [
        "print(string.find('p'))"
      ],
      "execution_count": 0,
      "outputs": [
        {
          "output_type": "stream",
          "text": [
            "0\n"
          ],
          "name": "stdout"
        }
      ]
    },
    {
      "cell_type": "code",
      "metadata": {
        "id": "YndJcTeDdQ4J",
        "colab_type": "code",
        "outputId": "cdda1868-846e-4f1c-f573-0a3e370702bd",
        "colab": {
          "base_uri": "https://localhost:8080/",
          "height": 35
        }
      },
      "source": [
        "print(string.find('t'))"
      ],
      "execution_count": 0,
      "outputs": [
        {
          "output_type": "stream",
          "text": [
            "-1\n"
          ],
          "name": "stdout"
        }
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {
        "id": "YkVlFDE1dSRh",
        "colab_type": "text"
      },
      "source": [
        "\n",
        "\n",
        "---\n",
        "\n"
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {
        "id": "WKAuFqwqdSzi",
        "colab_type": "text"
      },
      "source": [
        "## 10. Strip"
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {
        "id": "bNMVFWr8dUSl",
        "colab_type": "text"
      },
      "source": [
        "The strip function strips or removes the white spaces both from the starting and the ending of a string."
      ]
    },
    {
      "cell_type": "code",
      "metadata": {
        "id": "iK6st3AXdV8R",
        "colab_type": "code",
        "outputId": "bbc0a546-9deb-4d29-ab3b-0b92cb78624b",
        "colab": {
          "base_uri": "https://localhost:8080/",
          "height": 35
        }
      },
      "source": [
        "string = \"     programming is easy    \"\n",
        "string"
      ],
      "execution_count": 0,
      "outputs": [
        {
          "output_type": "execute_result",
          "data": {
            "text/plain": [
              "'     programming is easy    '"
            ]
          },
          "metadata": {
            "tags": []
          },
          "execution_count": 32
        }
      ]
    },
    {
      "cell_type": "code",
      "metadata": {
        "id": "w6iyIxh2dYJr",
        "colab_type": "code",
        "outputId": "6e39c256-e1c7-4d54-84ff-cbaef4e13e23",
        "colab": {
          "base_uri": "https://localhost:8080/",
          "height": 35
        }
      },
      "source": [
        "print(string.strip())"
      ],
      "execution_count": 0,
      "outputs": [
        {
          "output_type": "stream",
          "text": [
            "programming is easy\n"
          ],
          "name": "stdout"
        }
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {
        "id": "WKaqOD1_dZrJ",
        "colab_type": "text"
      },
      "source": [
        "\n",
        "\n",
        "---\n",
        "\n"
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {
        "id": "AYT7PeTCdbgL",
        "colab_type": "text"
      },
      "source": [
        "Hence above are the very important techniques or functions of Strings in Python. Some of the examples were referred from [Python Strings](https://www.gangboard.com/blog/python-string/). I have written this tutorial in a simple way such that everybody can understand and master the concepts of Strings in Python without prior programming knowledge or experience."
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {
        "id": "7WdDGsbVdfhv",
        "colab_type": "text"
      },
      "source": [
        "## Thank you"
      ]
    }
  ]
}